package com.freen.fadmin.service.jwt;

import com.freen.fadmin.entity.sysuser.SysUser;
import com.freen.fadmin.repository.sysuser.SysUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

public class JwtSysuserSecurityService implements UserDetailsService {
    @Autowired
    private SysUserRepository sysUserRepository;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        SysUser sysUser = sysUserRepository.findByPhone(s);
        if (sysUser == null){
            SysUser nameSysUser = sysUserRepository.findByName(s);
            if (nameSysUser ==null){
                throw new UsernameNotFoundException("用户名及手机号码不存在");
            }else {
                sysUser = nameSysUser;
            }
        }
        return sysUser;
    }
}
